// pages/Details/Details.js
Page({

 /**
  * 页面的初始数据
  */
 data: {
  // 类别数据
  allProducts: [],
  // 控制 loading 显示隐藏
  loading: true
 },
 // 静态数据
 static: {
  page: 1
 },

 // 获取类别列表
 getTopCategoryCode() {
  wx.request({
   url: 'https://starmid.minutestars.com/api/product4color/getPageProducts',
   method: "GET",
   data: {
    "topCategoryCode": '',
    "pageIndex": this.static.page,
    "pageSize": 8,
    "tableView": "ShowAreaItemProductsView4Color",
    "specialId": 748,
    "specialTopic": "",
    "searchWord": ""
   },
   success: (res) => {
    let { Result, Data } = res.data
    if (Result.Success) {
     Data.products.forEach((item, index) => {
      if (item.promoteDiscount) {
       item.promoteDiscount = Math.fround(item.price * item.promoteDiscount).toFixed(2)
      }
     })
     // 将请求到的数据给响应式数据
     this.setData({
      allProducts: [...this.data.allProducts, ...Data.products]
     })
     // 隐藏 loading
     this.setData({
      loading: this.data.loading = true
     })
     // 数据请求完毕关闭loading
     wx.hideLoading()
    }
   }
  })
 },

 /**
  * 生命周期函数--监听页面加载
  */
 onLoad(options) {
  wx.showLoading({
   title: '加载中...',
  })
  this.getTopCategoryCode()
 },
 /**
  * 页面上拉触底事件的处理函数
  */
 onReachBottom() {
  this.setData({
   loading: this.data.loading = false
  })
  this.static.page++
  this.getTopCategoryCode()
 },
})